#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;

class Solution {
public:

	int myAtoi(string s) {
		stringstream liu(s);
		int n = 0;
		liu >> n;
		return n;
	}

	int myAtoi(string s) {
		string number = "";
		for (int i = 0; i < s.size(); i++) {
			if (isdigit(s[i])) {
				int j = i;
				while (j < s.size() && isdigit(s[j]))
					number += s[j++];
				break;
			}
			else if ((s[i]=='-')&&(i + 1 < s.size() && isdigit(s[i + 1]))) {
				int j = i;
				number += s[j++];
				while (j < s.size() && isdigit(s[j]))
					number += s[j++];
				break;
			}
		}
		int res=0;
		bool flag = false;
		if (number[0] == '-') {
			flag = true;
			number=number.substr(1);
		}
		for (int j =0; j <number.size(); j++) {
			int num = number[j] - '0';
			if (res >= 214748364 && num > 7)
				return flag?-1*INT_MAX-1:INT_MAX;
			res = res * 10 + num;
		}
		return flag?-1*res:res;
	}
};

int main() {
	Solution s;
	s.myAtoi("               -4193 with words");
}
